package LeetcodeTest_thirty_three;
//1604.能否连接成数组

public class canFormArray
{
    public static void main(String[] args)
    {
        int[] arr={1,2,3};
        int[][]piecse={{1},{3,2}};
        System.out.println(Solution.canFormArray(arr,piecse));
    }
}
class Solution
{
    public static boolean canFormArray(int[] arr, int[][] pieces)
    {
        int i,j,k;
        int a,m,temp;
        boolean flag1,flag2;
        flag1=flag2=false;
        m=pieces.length;
        temp=0;
        for(i=0;i<arr.length;i++)
        {
            i=temp;
            a=arr[i];
            for(j=0;j<m;j++)
            {
                if(a==pieces[j][0])
                {
                    flag2=true;
                    for (k = 0; k < pieces[j].length; k++)
                    {
                        if(i<arr.length && arr[i]==pieces[j][k])
                        {
                            i++;
                            temp=i;
                        }
                        else
                        {
                            return flag1;
                        }
                    }
                }
            }
            if(flag2)
            {
                flag2 = false;
            }
            else
            {
                return false;
            }
        }
        return true;
    }
}